home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14114 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: newshost.cyberramp.net!news
  2. From: sinan@cyberramp.net (John L. Hollander)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Windows DLL
  5. Date: 11 Apr 1996 22:45:24 GMT
  6. Organization: Uno mas por favor
  7. Message-ID: <4kk224$4ns@newshost.cyberramp.net>
  8. References: <4kgqcg$g4p@reader2.ix.netcom.com>
  9. NNTP-Posting-Host: ramp1-29.cyberramp.net
  10. X-Newsreader: WinVN 0.99.5
  11.  
  12. In article <4kgqcg$g4p@reader2.ix.netcom.com>, bmwells@ix.netcom.com says...
  13. >
  14. >I can't use sscanf in my MS1.51 Visual C++ compiler when making a DLL.
  15. >What confuses me is the fact that strings can be used in DLLs.  So what
  16. >functions do I use to break strings down and manipulate them within
  17. >a DLL??
  18. >
  19.  
  20. This is a platform dependent question, so here is the platform dependent
  21. answer:
  22. In a DLL, DS != SS, since the DLL has its own heap, but uses the 
  23. callers stack. Therefore functions that take shortcuts and count on 
  24. DS == SS, don't work in a DLL. With some compilers, all of the C 
  25. functions that take a variable number of parameters, like sscanf(), 
  26. use a macro that assumes DS == SS. The Windows function wsprintf() 
  27. takes a variable number of arguments, but can be used in a DLL. It was 
  28. written as a Windows function from the ground up and doesn't make 
  29. these assumptions.
  30.  
  31. Your options are:
  32. - Rewrite the varargs.h or stdarg.h macros to accomodate use in DLL.
  33. - Do without the standard functions and write your own routines.
  34. - Find suitable Windows replacements and use them instead. 
  35.  
  36. Many people have run up against this same issue, I'm sure you would
  37. get better responses by posting to the comp.os.ms-windows.programmer
  38. groups. If you look around the net a little, I bet you could find
  39. Windows replacements for all of these functions. You might also look
  40. for a book on writing DLLs since there are other similar issues that 
  41. will bite you in the ass. If DS != SS, where are automatic variables
  42. stored? If you have a pointer to one you'll probably find out. What
  43. happens when you try and access an automatic array(or string)? [THINK
  44. FAR!] If you declare all your variables static, what happens when more 
  45. than one program calls your function? A DLL has its own heap, but it 
  46. only has one, no matter how many different programs call it. Is your
  47. function prepared to be reentrant?
  48.  
  49. -John
  50.  
  51.